package com.bawei.product.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
@Component
public class ThreadPoolExcuterConfig {


    @Bean
    public ThreadPoolExecutor itemInfoThreadPool(ItemInfoThradPoolProperties itemInfoThradPoolProperties){

        return new ThreadPoolExecutor(
                itemInfoThradPoolProperties.getCoreSize(),
                itemInfoThradPoolProperties.getMaxSize(),
                itemInfoThradPoolProperties.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(2000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()

        );
    }
    @Bean
    public ThreadPoolExecutor orderInfoThreadPool(){

        return new ThreadPoolExecutor(
                1,
                12,
                20,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(2000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()

        );
    }

}
